<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>小贷账单主表 管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 60px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">客户ID</div>
                    <div class="field">
                        <input name="cstId" id="cstId" type="text" class="ui-textbox" value="">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">贷款合同号</div>
                    <div class="field">
                        <input name="crCntNo" id="crCntNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">业务类型</div>
                    <div class="field">
                        <input name="loanBizTypCd" id="loanBizTypCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">贷款类型</div>
                    <div class="field">
                        <input name="crTypCd" id="crTypCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">贷款状态</div>
                    <div class="field">
                        <input name="loanStsCd" id="loanStsCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
 				<div class="fieldBox">
                    <div class="label">机构名称</div>
                    <div class="field">
                        <select name="loanId" id="loanId">
	                     <option selected="selected" value="">--全部--</option>
	                        <c:forEach items="${channelList }" var="ct">
	                        	<option value="${ct.id }">${ct.loanName }</option>
	                        </c:forEach>
                    	</select>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">放款账户</div>
                    <div class="field">
                        <select name="accountId" id="accountId">
	                     <option selected="selected" value="">--全部--</option>
	                        <c:forEach items="${accountList }" var="ct">
	                        	<option value="${ct.id }">${ct.accountName }</option>
	                        </c:forEach>
                    	</select>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">是否回购</div>
                    <div class="field">
                        <select name="isInform" id="isInform">
                            <option value="">--全部--</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </div>
                </div>
                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                    <span id="picUpload" onclick="picUpload();" class="sq-button sq-button-round">批量图片上传</span>
                    <span id="huiGou" onclick="huiGou();" class="sq-button sq-button-round">回购</span>
                    <span id="pushRepaymentPlan" onclick="pushRepaymentPlan();" class="sq-button sq-button-round">推送还款计划</span>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null, callback = null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/mcr/mcrBillM/initList.do?cstTypeCdList=1,2',
            method: 'get',
            columns: [
                {display: '客户名称', name: 'cstNm', minWidth: 100, align: 'left',
                    render:function(rowdata,rowindex,value){
                        return '<a href="javascript:;" onclick="showCstDtl('+rowdata.cstId+')"><span class="gridTip" title="客户查看">'+rowdata.cstNm+'</span></a>';
                    }
                },
                {display: '客户ID', name: 'cstId', minWidth: 180, align: 'left',
                    render:function(rowdata,rowindex,value){
                        return '<a href="javascript:;" onclick="showCstDtl('+rowdata.cstId+')"><span class="gridTip" title="客户查看">'+rowdata.cstId+'</span></a>';
                    }
                },
                {display: '贷款合同号', name: 'crCntNo', minWidth: 110, align: 'left',
                    render:function(rowdata,index,value){
                        return '<a href="javascript:;" style="cursor: pointer;" onclick="billDtl('+rowdata.id+')">'+rowdata.crCntNo+'</a>';
                    }
                },
                {display: '贷款金额', name: 'crAmtStr', minWidth: 80, align: 'right',
                    render:function(rowdata,index,value){
                        if(rowdata.actCrAmt){
                            return '&yen;'+rowdata.crAmtStr;
                        }
                    }
                },
                {display: '实际放款金额', name: 'actCrAmtStr', minWidth: 80, align: 'right',
                    render:function(rowdata,index,value){
                        if(rowdata.actCrAmtStr){
                            return '&yen;'+rowdata.actCrAmtStr;
                        }
                    }
                },
                {display: '业务类型', name: 'loanBizTypCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '贷款类型', name: 'crTypCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '客户类型', name: 'cstTypCd', width: 100, enabledSort:true,
                    render:function(rowData){
                        if(rowData.cstTypCd=="0"){
                            return "内部";
                        }else if(rowData.cstTypCd=="1"){
                            return "外部";
                        }else if(rowData.cstTypCd=="2"){
                            return "物流";
                        }
                    }
                },
                {display: '租赁期数', name: 'crPd', minWidth: 80, align: 'center',
                    render:function(rowdata,index,value){
                        return rowdata.crPd+rowdata.crPdUntCdNm;
                    }
                },
                {display: '放款日', name: 'crDtStr', minWidth: 100, align: 'center', },
                {display: '结清时间', name: 'stlDtStr', minWidth: 100, align: 'center', },
                {display: '贷款状态', name: 'loanStsCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '创建日期', name: 'crtTm', minWidth: 150, align: 'center', enabledSort: false,render:renderDate},
                {display: '机构名称', name: 'loanName', minWidth: 100, align: 'center', enabledSort: false},
                {display: '放款账号', name: 'loanAccountNm', minWidth: 150, align: 'center', enabledSort: false},
                {display: '机构账号名称', name: 'accountName', minWidth: 100, align: 'center', enabledSort: false},
                {display: '资方转我司原因', name: 'loanMsg', minWidth: 100, align: 'center', enabledSort: false},
                {display: '是否回购', name: 'isInform', width: 150, enabledSort:true,
                    render:function(rowData){
                        if(rowData.isInform=="1"){
                            return "是";
                        }else{
                            return "否";
                        }
                    }
                },
                {display: '回购本金', name: 'capAmt', minWidth: 80, align: 'right',
                    render:function(rowdata,index,value){
                        if(rowdata.capAmt){
                            return '&yen;'+rowdata.capAmt;
                        }
                    }
                },
                {display: '回购利息', name: 'intrAmt', minWidth: 80, align: 'right',
                    render:function(rowdata,index,value){
                        if(rowdata.intrAmt){
                            return '&yen;'+rowdata.intrAmt;
                        }
                    }
                },
                {display: '回购罚息', name: 'penaltyAmt', minWidth: 80, align: 'right',
                    render:function(rowdata,index,value){
                        if(rowdata.penaltyAmt){
                            return '&yen;'+rowdata.penaltyAmt;
                        }
                    }
                },
                {display: '回购总金额', name: 'totalAmt', minWidth: 80, align: 'right',
                    render:function(rowdata,index,value){
                        if(rowdata.totalAmt){
                            return '&yen;'+rowdata.totalAmt;
                        }
                    }
                },
                {display: '回购前是资方哪期资金', name: 'loanAccountName', minWidth: 100, align: 'center', enabledSort: false},
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
        });
        grid.setHeight(100);

        //业务类型
        $("#loanBizTypCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("loanBizTypCd").setData(${loanBizTypCdList});
        //贷款类型
        $("#crTypCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("crTypCd").setData(${crTypCdList});
        //贷款状态
        $("#loanStsCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("loanStsCd").setData(${loanStsCdList});

        $("#searchBar").ligerForm();

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
            form.setData({  //重置select等特殊表单
    		    "loanId":"",
    		    "accountId":""
    		  });
        });

        callback = function () {
            grid.reload();
        };

    });

    //查看账单详情
    function billDtl(billId){
        Add_navTab('MCR_BILL_M_'+billId,'小贷账单详情',"<%=path%>/mcr/mcrBillM/toBillDtlPage.do?id="+billId);
    }

    //查询客户详情
    function showCstDtl(_cstId){
        Add_navTab("MCR_BILL_M_"+_cstId, "客户信息", '<%=path%>/customer/cstbscinfo/toCustDetailPage.do?id='+_cstId, null);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }
    
  //新增
	function picUpload(){
		$.ligerDialog.SQopen({
            width: 1000,
            height:500,
            title : '批量图片上传',
            url:'<%=path%>/mcr/mcrBillM/picUploadListPage.do',
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                    text: "保存", type: 'ok', cls: 'l-dialog-btn-ok', 
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onOk = function () {}
                        if (Dialog.onOk) {
                        	Dialog.onOk();
                        }
                    }
                }, {
                    text: "取消", type: 'cancel', cls: 'l-dialog-btn-no', 
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                        if (Dialog.onCancel) {
                        	Dialog.onCancel()
                        };
                    }
                }
            ]
        });
	}
//回购
    function huiGou(){
        var data = new Array();//获取表单数据
        var grid = liger.get("ligergrid1");
        var selectedRows = grid.getSelectedRows();
        if(selectedRows.length < 1){
            UIUtils.alertError("请至少选择一条数据");
            return;
        }
        var ids = [];
        for(var i=0;i<selectedRows.length;i++){
            var id = selectedRows[i].id;
            ids[i] = id;
        }
        data["ids"] = JSON.stringify(ids);
        var url = '<%=path%>/mcr/mcrBillM/checkHuiGou.do';
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {ids: JSON.stringify(ids)},
            url: url,
            beforeSend: function(){
                wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
            },
            success:function(msg){
                wait_dialog.close();
                if(msg.success == 1){
                    $.ligerDialog.SQopen({
                        width: 1200,
                        height:500,
                        title : '回购',
                        url:'<%=path%>/mcr/mcrBillM/huiGouListPage.do?ids='+JSON.stringify(ids),
                        // 自定义buttons的时候 不要设置 fixButtons: true
                        buttons: [{
                            text: "回购", type: 'ok', cls: 'l-dialog-btn-ok',
                            onclick: function (item, Dialog) {
                                //在子页面里绑定 frameElement.dialog.onOk = function () {}
                                if (Dialog.onOk) {
                                    Dialog.onOk();
                                }
                            }
                        }, {
                            text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                            onclick: function (item, Dialog) {
                                //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                                if (Dialog.onCancel) {
                                    Dialog.onCancel()
                                };
                            }
                        }
                        ]
                    });
                }else{
                    $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                }
            }
        });
    }

    //推送还款计划
    function pushRepaymentPlan(){
        var url = '<%=path%>/mcr/mcrBillM/pushRepaymentPlan.do';
        $.ajax({
            type: 'post',
            dataType: 'json',
            url: url,
            beforeSend: function(){
                wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
            },
            success:function(msg){
                wait_dialog.close();
                if(msg.success == 1){
                    $.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
                }else{
                    $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                }
            }
        });
    }
</script>

</body>
</html>
